package io.renren.modules.category.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.common.utils.ConvertUtils;
import io.renren.modules.category.dao.TBrandDao;
import io.renren.modules.category.dto.TBrandDTO;
import io.renren.modules.category.entity.TBrandEntity;
import io.renren.modules.category.service.TBrandService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 品牌分类
 *
 * @author Mark sunlightcs@gmail.com
 * @since 1.0.0 2023-08-09
 */
@Service
public class TBrandServiceImpl extends CrudServiceImpl<TBrandDao, TBrandEntity, TBrandDTO> implements TBrandService {

    @Override
    public QueryWrapper<TBrandEntity> getWrapper(Map<String, Object> params){
        Long initialId = (Long)params.get("initialId");
        QueryWrapper<TBrandEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(Objects.nonNull(initialId), "initial_id", initialId);
        wrapper.orderByAsc("sort");
        return wrapper;
    }

    @Override
    public List<TBrandEntity> selectList(Map<String, Object> params){
        List<TBrandEntity> entityList = baseDao.selectList(getWrapper(params));
        return ConvertUtils.sourceToTarget(entityList, TBrandEntity .class);
    }


    public QueryWrapper<TBrandEntity> getWrapper2(Map<String, Object> params){
        String initialCode = (String)params.get("initialCode");
        QueryWrapper<TBrandEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(Objects.nonNull(initialCode), "initial_code", initialCode);
        wrapper.orderByAsc("sort");
        return wrapper;
    }

    @Override
    public List<TBrandEntity> selectListByCode(Map<String, Object> params){
        List<TBrandEntity> entityList = baseDao.selectList( getWrapper2(params));
        return ConvertUtils.sourceToTarget(entityList, TBrandEntity .class);
    }



}